package com.itheima.controller;

import com.itheima.domain.Pow;
import com.itheima.domain.Student;
import com.itheima.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

public class CentroController {
    private static final Logger LOGGER = LoggerFactory.getLogger(CentroController.class);
    public Scanner sc = new Scanner(System.in);
    private static User adminuser;

    public CentroController(User user) {
        this.adminuser = user;
    }


    // 客服的功能入口
    public final void start() throws Exception {
        while (true) {
            //1. 展示二级菜单列表
            System.out.println("********欢迎进入黑马信息管理系统********");
            System.out.println("1. 学生管理");
            System.out.println("2. 教师管理" + (adminuser.getPow().compareTo(Pow.TEACHER) > 0 ? "   (锁定!)" : ""));
            System.out.println("3. 权限管理"+ (adminuser.getPow().compareTo(Pow.ADMIN) > 0 ? "   (锁定!)" : ""));
            System.out.println("4. 退出");

            //2. 用户录入选项,匹配对应功能
            String option = sc.next();
            //3. 基于switch来进行菜单功能路由
            switch (option) {
                case "1":
                    (new StudentController(adminuser)).start();
                    break;
                case "2":
                    if (adminuser.getPow().compareTo(Pow.TEACHER) > 0){
                        System.out.println("权限不足!");
                        break;
                    }
                    (new TeacherController(adminuser)).start();
                    break;
                case "3":
                    if (adminuser.getPow().compareTo(Pow.ADMIN) > 0){
                        System.out.println("权限不足!");
                        break;
                    }
                    (new UserController(adminuser)).start();
                    break;
                case "4":
                    System.out.println("感谢使用黑马信息管理系统,再见!");
                    return;  // return 结束的当前方法!
                default:
                    System.out.println("输入有误!");
                    break;
            }
        }
    }

}
